/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.uml_generator.model.impl;

import java.util.Map;

import com.genia.toolbox.uml_generator.model.AbstractClassModel;
import com.genia.toolbox.uml_generator.model.AssociationCardinality;
import com.genia.toolbox.uml_generator.model.AssociationModel;
import com.genia.toolbox.uml_generator.model.AssociationType;
import com.genia.toolbox.uml_generator.model.AttributeModel;
import com.genia.toolbox.uml_generator.model.StereotypeModel;

/**
 * this class represent the associations entities from the xmi file.
 */
public class AssociationModelImpl
    extends AbstractObjectImpl
    implements AssociationModel
{

  /**
   * the {@link AssociationEnd} representing the current end of the association.
   */
  private AssociationEnd currentEnd;

  /**
   * the {@link AssociationEnd} representing the other end of the association.
   */
  private AssociationEnd otherEnd;

  /**
   * the {@link AssociationModel} representing the other end of the association.
   */
  private AssociationModel otherEndAssociation = null;



  /**
   * returns the type of the object associated object.
   * 
   * @return the {@link AbstractClassModel} begin the model of the associated
   *         object
   */
  public AbstractClassModel getAssociatedType()
  {
    return otherEnd.getType();
  }



  /**
   * returns the type of this association.
   * 
   * @return the type of this association
   */
  public AssociationType getAssociationType()
  {
    return currentEnd.getAssociationType();
  }



  /**
   * getter for the comment property.
   * 
   * @return the comment
   * @see com.genia.toolbox.uml_generator.model.impl.AbstractObjectImpl#getComment()
   */
  @Override
  public String getComment()
  {
    return otherEnd.getComment();
  }



  /**
   * returns the cardinality of this object. This means that if this method
   * returns ONE, the association is ONE TO ?.
   * 
   * @return the cardinality
   * @see com.genia.toolbox.uml_generator.model.impl.AssociationModel#getOtherCardinality()
   */
  public AssociationCardinality getCurrentCardinality()
  {
    return currentEnd.getCardinality();
  }



  /**
   * getter for the currentEnd property.
   * 
   * @return the currentEnd
   */
  public AssociationEnd getCurrentEnd()
  {
    return currentEnd;
  }



  /**
   * returns the type of the object from where the association start.
   * 
   * @return the {@link AbstractClassModel} begin the model of the associated
   *         object
   */
  public AbstractClassModel getCurrentType()
  {
    return currentEnd.getType();
  }



  /**
   * returns the list of {@link StereotypeModel} that mark this object.
   * 
   * @return the list of {@link StereotypeModel} that mark this object
   * @see com.genia.toolbox.uml_generator.model.impl.AbstractObjectImpl#getStereotypes()
   */
  @Override
  public Map<String, StereotypeModel> getStereotypes()
  {
    return otherEnd.getStereotypes();
  }



  /**
   * getter for the name property.
   * 
   * @return the name
   * @see com.genia.toolbox.uml_generator.model.impl.AbstractObjectImpl#getName()
   */
  @Override
  public String getName()
  {
    return otherEnd.getName();
  }



  /**
   * returns the type of the other end of this association.
   * 
   * @return the type of the other end of this association
   */
  public AssociationType getOtherAssociationType()
  {
    return otherEnd.getAssociationType();
  }



  /**
   * returns the cardinality of the other object. This means that if this method
   * returns ONE, the association is ? TO ONE.
   * 
   * @return the cardinality of the other object
   * @see com.genia.toolbox.uml_generator.model.impl.AssociationModel#getCardinality()
   */
  public AssociationCardinality getOtherCardinality()
  {
    return otherEnd.getCardinality();
  }



  /**
   * getter for the otherEnd property.
   * 
   * @return the otherEnd
   */
  public AssociationEnd getOtherEnd()
  {
    return otherEnd;
  }



  /**
   * returns the {@link AssociationModel} representing the other end of the
   * association.
   * 
   * @return the {@link AssociationModel} representing the other end of the
   *         association
   * @see com.genia.toolbox.uml_generator.model.impl.AssociationModel#getOtherEnd()
   */
  public AssociationModel getOtherEndAssociation()
  {
    return otherEndAssociation;
  }



  /**
   * returns the {@link AttributeModel} representing the qualifier for this
   * association, or <code>null</code> if this association has no qualifier.
   * 
   * @return the {@link AttributeModel} representing the qualifier for this
   *         association, or <code>null</code> if this association has no
   *         qualifier
   */
  public AttributeModel getQualifier()
  {

    return otherEnd.getQualifier();
  }



  /**
   * returns the UmlId of the object.
   * 
   * @return the UmlId of the object
   * @see com.genia.toolbox.uml_generator.model.impl.AbstractObjectImpl#getUmlId()
   */
  @Override
  public String getUmlId()
  {
    return otherEnd.getUmlId();
  }



  /**
   * returns wether this element is tagged with a particuliar value.
   * 
   * @param tag
   *          the value to check.
   * @return <code>true</code> if an only if the element is tagged with the
   *         value.
   * @see com.genia.toolbox.uml_generator.model.impl.AbstractObjectImpl#hasStereotype(java.lang.String)
   */
  @Override
  public boolean hasStereotype(String tag)
  {
    return otherEnd.hasStereotype(tag);
  }



  /**
   * setter for the currentEnd property.
   * 
   * @param currentEnd
   *          the currentEnd to set
   */
  public void setCurrentEnd(AssociationEnd currentEnd)
  {
    this.currentEnd = currentEnd;
  }



  /**
   * setter for the otherEnd property.
   * 
   * @param otherEnd
   *          the otherEnd to set
   */
  public void setOtherEnd(AssociationEnd otherEnd)
  {
    this.otherEnd = otherEnd;
  }



  /**
   * setter for the otherEndAssociation property.
   * 
   * @param otherEndAssociation
   *          the otherEndAssociation to set
   */
  public void setOtherEndAssociation(AssociationModel otherEndAssociation)
  {
    this.otherEndAssociation = otherEndAssociation;
  }

}
